package com.stat;

import java.util.Hashtable;

import com.info.ItemInfo;

public class CharacterItem {

	private Hashtable<ItemInfo, Integer> items;
	private int itemLimit;
	private int totalItems;
	
	public CharacterItem(int itemLimit){
		this.items = new Hashtable<ItemInfo, Integer>();
		this.itemLimit = itemLimit;
		this.totalItems = 0;
	}
	
	public boolean addItem(ItemInfo item){
		return this.addItem(item, 1);
	}
	
	public boolean addItem(ItemInfo item, int amout){
		if (totalItems >= itemLimit){
			return false;
		}
		if (this.items.containsKey(item)){
			this.items.put(item, this.items.get(item) + amout);
		}else{
			this.items.put(item, amout);
		}
		totalItems++;
		return true;
	}
	
	public void removeItem(ItemInfo item){
		this.removeItem(item, 1);
	}
	
	public void removeItem(ItemInfo item, int amount){
		if (this.items.containsKey(item)){
			this.items.put(item, this.items.get(item) - amount);
			if (this.items.get(item) < 1){
				this.items.remove(item);
			}
			totalItems--;
		}
	}
	
	public int getTotalItems(){
		return totalItems;
	}
	
	public int getTotalWeight(){
		int total = 0;
		for (ItemInfo i : this.items.keySet()){
			total += i.getWeight() * this.items.get(i).intValue();
		}
		return total;
	}
}
